package com.hbnu.service.impl;

import com.hbnu.mapper.GoodsMapper;
import com.hbnu.pojo.Good;
import com.hbnu.pojo.Util;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.atomic.AtomicReference;

@Service
@Slf4j
public class UtilService {

    @Autowired
    private GoodsMapper goodsMapper;

    public void insertMockGoodList(Util data){
        List<Good>goodList=data.getData();
        int k=goodsMapper.getGoodList().size();
        AtomicReference<Integer> id= new AtomicReference<>(k+1);
        goodList.stream().forEach(good -> {

            String gid=String.format("%0"+13+"d", id.getAndSet(id.get() + 1));
            String cid=new String("000000000007");
            goodsMapper.insertGood(gid,good.getGname(),cid,good.getPrice(),good.getDesc(),good.getSrc(),good.getNum(),good.getState());
        });

    }
}
